import axios from "axios";

const productFormModule = {
  namespaced: true,
  state: {
    first: {},
    second: {},
    third: {},
    fourth: {},
  },
  mutations: {
    SET_FIRST_DATA(state, data) {
      state.first = data;
    },
    SET_SECOND_DATA(state, data) {
      state.second = data;
    },
    CLEARN_DATA(state){
      const user={
        typeId:state.first.category,
        code:state.first.code,
        inventrory:state.first.inventory,
        price:state.first.price,
        remark:state.first.remark,
        name:state.first.name,
        unit:state.second.unit,
        shelves:state.second.publishStatus,
        recommend:state.second.recommendStatus,
        newProduct:state.second.newStatus,
        sale:state.first.sale,
        audit:"未审核"
      }
      console.log(user)
      axios.post('http://localhost:8080/Goods/addGood',user).then((res)=>{
        console.log(res)
      })
      state.first={}
      state.second={}
    },
    UPDATE_BASIC_INFO(state, payload) {
      state.basicInfo = payload;
    },
    UPDATE_PROMOTION(state, payload) {
      state.promotion = payload;
    },
    UPDATE_ATTRIBUTE(state, payload) {
      state.attribute = payload;
    },
    UPDATE_RELATION(state, payload) {
      state.relation = payload;
    }
    // SET_THIRD_DATA(state, data) {
    //   state.third = data;
    // },
    // SET_FOURTH_DATA(state, data) {
    //   state.fourth = data;
    // }
  },
  actions: {
    SET_first_DATA({ commit }, data) {
      // console.log(data)
      commit('SET_FIRST_DATA', data);
    },
    SET_second_DATA({ commit }, data) {
      console.log(data)
      commit('SET_SECOND_DATA', data);
    },
    // SET_third_DATA({ commit }, data) {
    //   console.log(data)
    //   commit('SET_THIRD_DATA', data);
    // },
    // SET_fourth_DATA({ commit }, data) {
    //   console.log(data)
    //   commit('SET_FOURTH_DATA', data);
    // },
    CLEARN_ALL({ commit }){
      commit('CLEARN_DATA');
    }
  },
  getters:{
    get_FIRST_tData(state) {
      return state.first;
  },
  get_SECOND_tData(state) {
    return state.second;
},
  }
};
export default productFormModule;
